package com.ccq.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.ccq.domain.User;

public class JAVA8New {
	public static void main(String[] args) {
//		sort();
//		sum();
		Predicate<String> predicate = s -> s.equals("1");
//		boolean test = predicate.test(111);
//		System.out.println(test);
		List<String> asList = Arrays.asList("1","3","4","1","3");
//		System.out.println(asList.stream().anyMatch(predicate));	
//		System.out.println(asList.contains("1"));
//		List<String> collect = asList.stream().distinct().collect(Collectors.toList());
		List<String> collect2 = asList.stream().limit(1).collect(Collectors.toList());
		List<String> collect3 = asList.stream().skip(2).collect(Collectors.toList());
		boolean anyMatch = asList.stream().anyMatch(p->p.equals("31"));
		System.out.println(anyMatch);
//		for (String string : collect3) {
//			System.out.println(string);
//		}
	}
	
	public static void sort(){
		List<User> list = new ArrayList<>();
		User u1 = new User("asaw", "1", "1");
		User u2 = new User("zsaw", "23", "23");
		User u3 = new User("xsaw", "13", "13");
		User u4 = new User("csaw", "3", "4");
		list.add(u1);
		list.add(u2);
		list.add(u3);
		list.add(u4);
		// Collections.sort(list, new Comparator<User>() {
		// @Override
		// public int compare(User o1, User o2) {
		// return Integer.parseInt(o1.getAge())-Integer.parseInt(o2.getAge());
		// }
		// });
		list.sort((a, b) -> Integer.parseInt(a.getAge()) - Integer.parseInt(b.getAge()));
		for (User string : list) {
			System.out.println(string.getAge());
		}

		List<String> names = Arrays.asList("12", "2", "3", "5");
		Collections.sort(names, (a, b) -> Integer.parseInt(b) - Integer.parseInt(a));
	}
	
	static void  sum(){
		List<Integer> asList = Arrays.asList(1,2,4,5,6);
		Integer reduce1= asList.parallelStream().reduce(0,Integer::sum);
		Integer reduce2 = asList.stream().reduce(0,Integer ::sum);
		System.out.println(reduce1+"----"+reduce2);
	}
	
}
